//
//  SystemFeedback.m
//  cutter
//
//  Created by mac on 16/4/6.
//  Copyright © 2016年 e360. All rights reserved.
//

#import "SystemFeedback.h"


//
@interface SystemFeedbackTag : UIButton
@end
@implementation SystemFeedbackTag
-(void)setSelected:(BOOL)selected{
    [super setSelected:selected];
    if (selected) {
        [self setBackgroundColor:[UIColor colorWithHex:0x4794EF]];
    }else{
        [self setBackgroundColor:[UIColor colorWithHex:0xEFEFEF]];
    }
}
@end


//
@implementation SystemFeedback
-(void)viewDidLoad {
    [super viewDidLoad];
    //
    [self.proposeView addTarget:self action:@selector(tagTouch:) forControlEvents:UIControlEventTouchUpInside];
    [self.errorView addTarget:self action:@selector(tagTouch:) forControlEvents:UIControlEventTouchUpInside];
    [self.helpView addTarget:self action:@selector(tagTouch:) forControlEvents:UIControlEventTouchUpInside];
    [self tagTouch:self.proposeView];
}
-(void)tagTouch:(UIButton*)sender{
    [self.proposeView setSelected:NO];
    [self.errorView setSelected:NO];
    [self.helpView setSelected:NO];
    [sender setSelected:YES];
}
- (IBAction)commitTouch:(id)sender {
    [self.detailView resignFirstResponder];
    [self.nameView resignFirstResponder];
    //
    if ([self.nameView.text length] > 0 && [self.detailView.text length] > 0) {
        id user = [TMGlobal valueForKey:@"user"];
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        [dic setValue:[user objectForKey:@"id"] forKey:@"userid"];
        [dic setValue:self.detailView.text forKey:@"content"];
        [dic setValue:self.nameView.text forKey:@"title"];
        if (self.proposeView.selected) {
            [dic setValue:@(0) forKey:@"tag"];
        }
        if (self.errorView.selected) {
            [dic setValue:@(1) forKey:@"tag"];
        }
        if (self.helpView.selected) {
            [dic setValue:@(2) forKey:@"tag"];
        }
        //
        if ([AppData ideaEdit:dic]) {
            [UIAlertController show:nil message:@"感谢您的意见！" buttons:nil handler:nil];
            [self tagTouch:self.proposeView];
            [self.detailView setText:@""];
            [self.nameView setText:@""];
        }
    }
}
@end
